import axios from "axios";
import NProgress from "nprogress";
import 'nprogress/nprogress.css'

const requestMock = axios.create({
    baseURL: '',
    timeout: 5000
})

requestMock.interceptors.request.use(config => {
    NProgress.start()
    return config
}, error => {
    return Promise.reject(error)
})

requestMock.interceptors.response.use(response => {
    NProgress.done()
    if (response.data.code === 200) {
        NProgress.done()
        return response.data.data
    }
    return Promise.reject({message: response.data.message})
}, error => {
    return Promise.reject(error)
})

export default requestMock